﻿using System;
using System.ComponentModel;
using System.Linq;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Guan.CMS.Model.Entities
{
    public class Media
    {
        public int Id { get; set; }
        /// <summary>
        /// 文件名
        /// </summary>
        [DisplayName("文件名")]
        public string Name { get; set; }

        /// <summary>
        /// 扩展名
        /// </summary>
        [DisplayName("扩展名")]
        public string ExtName { get; set; }

        /// <summary>
        /// 文件路径
        /// </summary>
        [DisplayName("文件路径")]
        public string Path { get; set; }

        /// <summary>
        /// 文件大小
        /// </summary>
        [DisplayName("文件大小")]
        public long Size { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [DisplayName("创建时间")]
        public DateTime CreatedTime { get; set; }

        /// <summary>
        /// 文件类型
        /// </summary>
        [NotMapped,DisplayName("类型")]
        public string MediaType
        {
            get
            {
                var imageExtList = new[] {"jpg", "jpeg", "png", "gif", "bmp"};
                var documentExtList = new[] {"txt", "doc", "docx", "xls", "xlsx", "ppt", "pptx"};
                if (imageExtList.Contains(this.ExtName))
                {
                    return "image";
                }
                if (documentExtList.Contains(this.ExtName))
                {
                    return "document";
                }
                return "file";
            }
        }

        /// <summary>
        /// 完整文件名
        /// </summary>
        [NotMapped,DisplayName("文件名")]
        public string FullName
        {
            get { return this.Name + "." + this.ExtName; }
        }
    }
}